package com.tianda.his.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tianda.his.modules.system.entity.SysMenu;
import com.tianda.his.modules.system.entity.SysRoleMenu;
import com.tianda.his.modules.system.mapper.SysMenuMapper;
import com.tianda.his.modules.system.mapper.SysRoleMenuMapper;
import com.tianda.his.modules.system.service.ISysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 菜单权限表 服务实现类
 * </p>
 *
 * @author jinken
 * @since 2025-09-12
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public List<Long> getMenuIdsByRoleId(Long roleId) {
        LambdaQueryWrapper<SysRoleMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysRoleMenu::getRoleId, roleId);

        List<SysRoleMenu> sysRoleMenus = sysRoleMenuMapper.selectList(queryWrapper);

        List<Long> menuIds = sysRoleMenus.stream().map(SysRoleMenu::getMenuId).toList();

        return menuIds;
    }
}
